package com.banciyuan.bcywebview.biz.zanlist.decoration;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by squall on 2016/6/28.
 */
public class ZanItemOffsetDecoration extends RecyclerView.ItemDecoration {
    private int offset;

    public ZanItemOffsetDecoration(int offset) {
        this.offset = offset;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        int position = parent.getChildAdapterPosition(view);
        int index = parent.getAdapter().getItemViewType(position);
        if ((index == 1) || (index >= 30 && index <= 36)) {
            outRect.top = offset;
            position = position - 1;
            if (position % 3 == 0) {
                outRect.left = 0;
                outRect.right = offset * 2 / 3;
            } else if (position % 3 == 1) {
                outRect.left = offset / 3;
                outRect.right = offset / 3;
            } else if (position % 3 == 2) {
                outRect.left = offset * 2 / 3;
                outRect.right = 0;
            }
        }
    }
}